# !/usr/bin/env python
# encoding: utf-8


"""
  @author: gaogao
  @file: receive_server_msg_thread.py
  @time: 2022/3/7 16:29
  @desc:
"""

from PyQt5.QtCore import QThread
from ATS.socketServer import SocketServer_constant
from PyQt5.QtCore import pyqtSignal


class ReceiveServerMsgThread(QThread):
    complete = pyqtSignal()
    velox_state = pyqtSignal()
    gui_state = pyqtSignal()

    def __init__(self, server):
        super().__init__()
        self.sock_server = server
        self.flag = True

    def run(self) -> None:
        while True:
            if self.flag and self.sock_server:
                msg = self.sock_server.recv(SocketServer_constant.MAX_MSG_LEN).decode("utf-8")
                print("msg", msg)
                if msg == SocketServer_constant.COMPLETE_CMD:
                    self.complete.emit()
                if msg == "Velox Success":
                    self.velox_state.emit()
                if msg == "Client Success":
                    self.gui_state.emit()
            else:
                break
